#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QIcon donk(":/image/donk.jpg");
    ui->pushButton->setIcon(donk);
    ui->pushButton->setIconSize(QSize(50,50));
    QFont f1;
    f1.setPointSize(18);
     ui->pushButton->setFont(f1);

    QIcon up(":/image/up.png");
    ui->pushButton_up->setIcon(up);
    ui->pushButton_up->setIconSize(QSize(50,50));
    QIcon right(":/image/right.png");
    ui->pushButton_right->setIcon(right);
    ui->pushButton_right->setIconSize(QSize(50,50));
    QIcon left(":/image/left.png");
    ui->pushButton_left->setIcon(left);
    ui->pushButton_left->setIconSize(QSize(50,50));
    QIcon down(":/image/down.png");
    ui->pushButton_down->setIcon(down);
    ui->pushButton_down->setIconSize(QSize(50,50));
    //设置快捷键
    ui->pushButton_up->setShortcut(QKeySequence("w"));
    ui->pushButton_down->setShortcut(QKeySequence("s"));
    ui->pushButton_left->setShortcut(Qt::Key_A);
    ui->pushButton_right->setShortcut(Qt::Key_D+Qt::CTRL);
    //设置鼠标点击连发
    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()-5,rect.width(),rect.height());
    qDebug()<<"up";
}
void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()+5,rect.width(),rect.height());
    qDebug()<<"down";
}
void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()-5,rect.y(),rect.width(),rect.height());
    qDebug()<<"left";
}
void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()+5,rect.y(),rect.width(),rect.height());
    qDebug()<<"right";
}

